var t = require("../../../../@babel/runtime/helpers/slicedToArray"), e = getApp();

Component({
    properties: {
        activity_list: {
            type: Array
        },
        type: {
            type: String,
            value: ""
        },
        width: {
            type: Number
        }
    },
    observers: {
        activity_list: function(t) {
            t && 0 !== t.length && (this.setData({
                activity: t
            }), this.getData(), this.show());
        }
    },
    data: {
        show: !1,
        activity: [],
        list: [ {
            title: "认购活动",
            value: 0
        }, {
            title: "待发放",
            value: 3
        }, {
            title: "认购失败",
            value: -1
        }, {
            title: "结算重开",
            value: 6
        }, {
            title: "已完成",
            value: 5
        } ],
        active: 0,
        activedata: 0,
        currentIndex: 0,
        scroll_left: 0,
        left_clix: 0,
        timeId: null
    },
    methods: {
        show: function() {
            var t = this;
            this.data.activity_list && console.log(this.data.activity_list), console.log(this.data.activity_list, "activity_list======"), 
            this.data.timeId && this.setData({
                timeId: null
            }), this.data.timeId = setTimeout(function() {
                t.setLine(0);
            }, 500);
        },
        onChange: function(t) {
            console.log(t), this.setData({
                activedata: t.detail.name
            }), this.getData();
        },
        handle: function(t) {
            var e = t.currentTarget.offsetLeft;
            e > this.data.width / 2 ? (e -= 175, this.setData({
                scroll_left: e
            })) : e < this.data.width / 2 && this.setData({
                scroll_left: 0
            }), this.setData({
                currentIndex: t.currentTarget.dataset.index,
                activedata: t.currentTarget.dataset.id
            }), this.getData(), this.setLine(t.currentTarget.dataset.index);
            var a = wx.createSelectorQuery();
            a.select(t).boundingClientRect(), a.selectViewport().scrollOffset(), a.exec(function(t) {
                console.log(t);
            });
        },
        getData: function() {
            var t = this, a = "";
            if ("home" == this.data.type) a = "plugin.subscription.frontend.modules.activity.controllers.detail.index"; else {
                var i = this.data.list.filter(function(t) {
                    return 1 !== t.value;
                });
                this.setData({
                    list: i
                }), a = "plugin.subscription.frontend.modules.member.controllers.stage.index";
            }
            var s = {
                stage_status: this.data.active
            };
            0 == this.data.activedata ? s.activity_id = this.data.activity[0].id : s.activity_id = this.data.activedata, 
            e._postNetWork({
                url: e.getNetAddresss(a),
                data: s,
                success: function(a) {
                    0 == a.data.result && e.tips(a.data.msg);
                    var i = 0;
                    i = 0 == t.data.activedata ? t.data.activity[0].id : t.data.activedata, t.triggerEvent("activeInfo", {
                        data: a.data.data,
                        active: t.data.active,
                        activity_id: i,
                        stage_status: t.data.active
                    });
                }
            });
        },
        change: function(t) {
            var e = t.currentTarget.dataset.i;
            if (this.data.active == e) return !1;
            this.setData({
                active: e
            }), this.getData();
        },
        setLine: function(e) {
            var a = this;
            Promise.all([ this.getAllRect(".box-item"), this.getRect(".current_line") ]).then(function(i) {
                var s = t(i, 2), n = s[0], c = void 0 === n ? [] : n, r = s[1], l = c[e];
                if (null != l) {
                    var o = c.slice(0, e).reduce(function(t, e) {
                        return t + e.width;
                    }, 0);
                    o += (l.width - r.width) / 2, a.setData({
                        left_clix: o
                    });
                }
            }).catch(function(t) {
                console.log("err=>", t);
            });
        },
        getAllRect: function(t) {
            var e = this;
            return new Promise(function(a) {
                wx.createSelectorQuery().in(e).selectAll(t).boundingClientRect().exec(function() {
                    var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
                    return a(t[0]);
                });
            });
        },
        getRect: function(t) {
            var e = this;
            return new Promise(function(a) {
                wx.createSelectorQuery().in(e).select(t).boundingClientRect().exec(function() {
                    var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
                    return a(t[0]);
                });
            });
        }
    },
    lifetimes: {
        attached: function() {
            var t = wx.createSelectorQuery();
            t.select(".status-box").boundingClientRect(function(t) {
                console.log(t, "status-box");
            }), t.exec(), this.setData({
                show: !0
            });
        }
    }
});